
*****************************************************************************
*** Jessica Fortin-Rittberger, Philipp Harfst & Sarah C. Dingler (2017): The*
*** costs of electoral fraud: establishing the link between electoral********
*** integrity, winning an election, and satisfaction with democracy, Journal*
*** of Elections, Public Opinion and Parties, DOI:10.1080/17457289.2017.*****
*** 1310111 - Do-File to Replicate Models and Graphs ************************
*****************************************************************************
[Copy Path here use Replication_Data_Fortin-Rittberger_Harfst_Dingler_Electoral fraud _JEPOP.dta]


*******************************************************************************
*** Analysis******************************************************************* 
*** 1) multivariate models to estimate the effects of fraud on SWD*************
*** 2) Figures and Graphs******************************************************
*******************************************************************************

*******************************************************************************
*** 1) multivariate models to estimate the effects of fraud on SWD*************
*** STEP 2: multivariate models to estimate the effects of fraud on SWD********
*******************************************************************************
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand if LOGgdpcap~=.|| country:, intpoints(20)  intmethod(mcaghermite) 
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave|| country:, intpoints(20)  intmethod(mcaghermite) 
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave ti_cpi || country:, intpoints(20)  intmethod(mcaghermite) 
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave  Zwinner#c.qed_stand || country:, intpoints(20) intmethod(mcaghermite) 
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave  thirdwave#c.qed_stand || country:, intpoints(20) intmethod(mcaghermite) 



*******************************************************************************
*** 2) Figures and Graphs******************************************************
*** Graph 1: Effects of electoral fraud on SWD*********************************
*******************************************************************************

collapse (mean) demo qed_stand Z3019_re Z3000 Z1003 Z3001 (semean) qed_stand_se = qed_stand Z3019_re_se = Z3019_re Z3000_se = Z3000 Z3001_se = Z3001, by(Z1004)

twoway (scatter Z3019_re  qed_stand , msymbol(circle)  msize(large) jitter(5) mlabel(Z1004)) (lfit Z3019_re qed_stand )

pwcorr  Z3019_re qed_stand, sig star(.05) obs

clear

*******************************************************************************
*** Figure 2: THE EFFECTS OF MAGNITUDE OF PROBLEMS IN ELECTIONS ON SATISFACTION 
*** WITH DEMOCRACY, PREDICTED PROBABILITIES************************************
*******************************************************************************

[Copy Path here use Replication_Data_Fortin-Rittberger_Harfst_Dingler_Electoral fraud _JEPOP.dta]

ologit Z3019_re  Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand gdpcapwb laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave ti_cpi, robust cluster(Z1003)
prgen qed_stand, gen(econ) ci level(90)
 

graph twoway line econp1 econp2 econp3 econp4 econp1lb econp1ub econp2lb econp2ub econp3lb econp3ub econp4lb econp4ub econx,	///
ytitle(Probability) xtitle(Magnitude of Problems in Election QED (index)) ///
legend(cols(2) position(6)	///
label(1 "not at all satisfied") label(2 "not very satisfied") label(3 "fairly satisfied") label(4 "very satisfied"))
 

*******************************************************************************
***Figure 3:  MARGINAL EFFECTS OF WINNING AND LOSING ACROSS MAGNITUDE OF******* 
***PROBLEMS IN ELECTIONS ON SATISFACTION WITH DEMOCRACY************************
*******************************************************************************
ologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 ib0.Zwinner qed_stand LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave  Zwinner#c.qed_stand

quietly margins Zwinner, at(qed_stand=(-0.37(-0.04)1.83)) predict(outcome(1)) 
marginsplot, recast(line) title ("Marginal effects of winning/losing an election on the probability of not being very satisfied", size(small)) ytitle(Probability of not beeing very satisfied) xtitle(Magnitude of Problems in Election QED (index))

quietly margins Zwinner, at(qed_stand=(-0.37(-0.04)1.83)) predict(outcome(3))
marginsplot, recast(line) title ("Marginal effects of winning/losing an election on the probability of being fairly satisfied", size(small))    ///
ytitle(Probability of not beeing fairly satisfied) xtitle(Magnitude of Problems in Election QED (index)) legend (label (1 "Did not vote for winner"))



*******************************************************************************
*** Figure 4: MARGINAL EFFECTS OF THIRD WAVE COUNTRIES ACROSS MAGNITUDE OF****
*** PROBLEMS IN ELECTIONS ON SATISFACTION WITH DEMOCRACY***********************
*******************************************************************************
ologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 ib0.thirdwave qed_stand LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage Zwinner thirdwave#c.qed_stand, or

quietly margins thirdwave, at(qed_stand=(-0.37(-0.04)1.83)) predict(outcome(1)) 
marginsplot, recast(line) title ("Marginal effects of winning/losing an election on the probability of being not at all satisfied", size(small)) ytitle(Probability of being not at all satisfied) xtitle(Magnitude of Problems in Election QED (index)) 
	

quietly margins thirdwave, at(qed_stand=(-0.37(-0.04)1.83)) predict(outcome(4))
marginsplot, recast(line) title ("Marginal effects of third wave countries on the probability of being very satisfied", size(small)) ytitle(Probability of being not at all satisfied) xtitle(Magnitude of Problems in Election QED (index)) legend(cols(2) position(6) )   




*******************************************************************************
*** Appendix*******************************************************************
*** Robustness checks********************************************************** 
*** Alternative specifications of the article�s main independent variable****** 
*** Magnitude of problems in election):SA2 DUMMIES****************************
*******************************************************************************
clear
[Copy Path here use Replication_Data_Fortin-Rittberger_Harfst_Dingler_Electoral fraud _JEPOP.dta]


generate SA2_dummy=.
replace SA2_dummy=0 if sa2==0
replace SA2_dummy=1 if sa2==1
replace SA2_dummy=1 if sa2==2
replace SA2_dummy=1 if sa2==3


meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 ib0.Zwinner ib0.SA2_dummy if LOGgdpcap~=.|| country:, intpoints(20)  intmethod(mcaghermite) 
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 ib0.Zwinner ib0.SA2_dummy LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave|| country:, intpoints(20)  intmethod(mcaghermite) 
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 ib0.Zwinner ib0.SA2_dummy LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave ti_cpi || country:, intpoints(20)  intmethod(mcaghermite) 
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 ib0.Zwinner ib0.SA2_dummy LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave  ib0.Zwinner#ib0.SA2_dummy || country:, intpoints(20) intmethod(mcaghermite) 
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 ib0.Zwinner ib0.SA2_dummy LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave  ib0.thirdwave#ib0.SA2_dummy || country:, intpoints(20) intmethod(mcaghermite) 


***Pseudo R ***
ologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner SA2_dummy if LOGgdpcap~=.
ologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner SA2_dummy LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave 
ologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner SA2_dummy LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave
ologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner SA2_dummy LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave Zwinner#SA2_dummy
ologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner SA2_dummy LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave thirdwave#SA2_dummy


*******************************************************************************
*** Robustness checks********************************************************** 
*** Alternative specifications of the article�s main independent variable****** 
*** Magnitude of problems in election)VDEM INDEX*******************************
*******************************************************************************

***to have the same amount of observations accorss models drop when ti_cpi missing***

drop if ti_cpi==.

meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner Vdem if LOGgdpcap~=.  || country:, intpoints(10)  intmethod(mcaghermite)
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner Vdem LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage i.thirdwave|| country:, intpoints(20)  intmethod(mcaghermite) 
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner Vdem LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage i.thirdwave ti_cpi || country:, intpoints(20)  intmethod(mcaghermite)
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner Vdem LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage i.thirdwave  Zwinner#c.Vdem || country:, intpoints(20) intmethod(mcaghermite)
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner Vdem LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage i.thirdwave  thirdwave#c.Vdem || country:, intpoints(20) intmethod(mcaghermite)



***Pseudo R***

ologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner Vdem if LOGgdpcap~=.
ologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner Vdem LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave
ologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner Vdem LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave
ologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner Vdem LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave Zwinner#c.Vdem 
ologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner Vdem LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave thirdwave#c.Vdem



*******************************************************************************
*** Robustness checks********************************************************** 
*** Alternative specifications of the article�s main independent variable****** 
*** Magnitude of problems in election)MARGIN OF MAJORITY WITH DPI DATA*********
*******************************************************************************



meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand margin_majority  if LOGgdpcap~=.|| country:, intpoints(20)  intmethod(mcaghermite) 
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand margin_majority LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave|| country:, intpoints(20)  intmethod(mcaghermite) 
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand margin_majority LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave ti_cpi || country:, intpoints(20)  intmethod(mcaghermite) 
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand margin_majority LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave  Zwinner#c.qed_stand || country:, intpoints(20) intmethod(mcaghermite) 
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand margin_majority LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave  thirdwave#c.qed_stand || country:, intpoints(20) intmethod(mcaghermite) 
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand margin_majority LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave  thirdwave#c.margin_majority || country:, intpoints(10) intmethod(mcaghermite)

***Pseudo R***

ologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand margin_majority  if LOGgdpcap~=.
ologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand margin_majority LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave
ologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand margin_majority LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave ti_cpi  
ologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand margin_majority LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave  Zwinner#c.qed_stand  
ologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand margin_majority LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave  thirdwave#c.qed_stand 
ologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand margin_majority LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave  thirdwave#c.margin_majority 



*******************************************************************************
*** Robustness checks********************************************************** 
*** Alternative specifications of the article�s main independent variable****** 
*** Magnitude of problems in election)margin of victory from VDEM**************
*******************************************************************************


meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand margin_victory if LOGgdpcap~=. || country:, intpoints(10)  intmethod(mcaghermite)
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand margin_victory LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave|| country:, intpoints(10)  intmethod(mcaghermite) 
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand margin_victory LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave ti_cpi || country:, intpoints(10)  intmethod(mcaghermite)
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand margin_victory LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave  Zwinner#c.qed_stand || country:, intpoints(10) intmethod(mcaghermite)
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand margin_victory LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave  thirdwave#c.qed_stand || country:, intpoints(10) intmethod(mcaghermite)
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand margin_victory LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave  thirdwave#c.margin_victory || country:, intpoints(10) intmethod(mcaghermite)


***Pseudo R
ologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand margin_victory if LOGgdpcap~=.
ologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand margin_victory LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave
ologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand margin_victory LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave ti_cpi 
ologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand margin_victory LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave  Zwinner#c.qed_stand 
ologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand margin_victory LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave  thirdwave#c.qed_stand 
ologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand margin_victory LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave  thirdwave#c.margin_victory 



*******************************************************************************
*** Robustness check: Fixed-effects model with country dummies ****************
*** Country dummies, clustering variable at election study level **************
*******************************************************************************


tabulate country, generate(c)


meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand c2 c4 c5 c6 c7 c8 c10 c11 c12 c14 c15 c17 c18 c19 c20 c22 c24 c25 c26 c27 c28 c29 c30 c31 c33 c34 c35 c36 c37 c38 c39 c40 c41  if LOGgdpcap~=. || Z1004:, intpoints(20)  intmethod(mcaghermite) 
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave c2 c4 c5 c6 c7 c8 c10 c11 c12 c14 c15 c17 c18 c19 c20 c22 c24 c25 c26 c27 c28 c29 c30 c31 c33 c34 c35 c36 c37 c38 c39 c40 c41 || Z1004:, intpoints(20)  intmethod(mcaghermite) 
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave ti_cpi c2 c4 c5 c6 c7 c8 c10 c11 c12 c14 c15 c17 c18 c19 c20 c22 c24 c25 c26 c27 c28 c29 c30 c31 c33 c34 c35 c36 c37 c38 c39 c40 c41  || Z1004:, intpoints(20)  intmethod(mcaghermite) 
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave  Zwinner#c.qed_stand  c2 c4 c5 c6 c7 c8 c10 c11 c12 c14 c15 c17 c18 c19 c20 c22 c24 c25 c26 c27 c28 c29 c30 c31 c33 c34 c35 c36 c37 c38 c39 c40 c41  || Z1004:, intpoints(20) intmethod(mcaghermite) 
meologit Z3019_re Z2001 Z2002 Z2003 Z3020 Z3013 Z3001 Zwinner qed_stand LOGgdpcap laginflation  laggrowth dpi_system2 electoral dpi_partyage thirdwave  thirdwave#c.qed_stand c2 c4 c5 c6 c7 c8 c10 c11 c12 c14 c15 c17 c18 c19 c20 c22 c24 c25 c26 c27 c28 c29 c30 c31 c33 c34 c35 c36 c37 c38 c39 c40 c41  || Z1004:, intpoints(20) intmethod(mcaghermite) 





